﻿using System.Collections.Generic;
using System.Linq;

namespace WeBlog.Models
{
    public static class RoleRepository {                
        public static Role Admin = new Role( RoleValues.Admin, Role.Admin, "Full control" );
        public static Role Editor = new Role(RoleValues.Editor, Role.Editor, "Can Edit posts, including other peoples posts");
        public static Role Author = new Role(RoleValues.Author, Role.Author, "Can Edit own posts");
        public static Role Contributor = new Role(RoleValues.Contributor, Role.Contributor, "Can leave comments, contribute ideas");
        public static Role Subscriber = new Role(RoleValues.Subscriber, Role.Subscriber, "Subscribes to newsletter, rss feeds");

        public static IEnumerable<Role> FindRoles()
        {
            yield return Admin;
            yield return Editor;
            yield return Author;
            yield return Contributor;
            yield return Subscriber;
        }

        public static Role FindByName( string name )
        {
            return FindRoles().Single(x => x.Name == name);
        }
    }

    public static class RoleValues
    {
        public static int Admin = 1;
        public static int Editor = 2;
        public static int Author = 4;
        public static int Contributor = 8;
        public static int Subscriber = 16;
    }
}